package com.hanbang.taitaigou.ui.activity.aboutme.setting;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanbang.taitaigou.R;
import com.hanbang.taitaigou.model.GetContact;
import com.hanbang.taitaigou.ui.activity.base.BaseActivity;
import com.hanbang.taitaigou.utils.http.HttpCallBack;
import com.hanbang.taitaigou.utils.http.HttpRequestParams;
import com.hanbang.taitaigou.utils.http.JsonHelper;
import com.hanbang.taitaigou.utils.other.ObjectUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 联系客服
 * Created by fanxin on 2016/3/22.
 */
public class ContactCustomerServiceActivity extends BaseActivity {

    /**
     * 电话
     **/
    private TextView tv_tel;
    private String tel;


    private GetContact getContact = null;

    /**
     * 拨号
     ***/
    private LinearLayout ll_tel;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about_setting_contact_customer_service);
        initView();
        setOnClickListener();
        getContact();
    }

    /**
     * 获取联系我们
     */
    private void getContact() {
        HttpRequestParams httpRequestParams = new HttpRequestParams("GetContact");
        httpManager.post(httpRequestParams, new HttpCallBack<String>(this, "正在加载...") {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    if (jsonObject.getInt("status") == 1) {
                        JSONArray js = jsonObject.getJSONArray("result");
                        if(js.length()>0){
                            getContact = JsonHelper.parseObject(js.getJSONObject(0),GetContact.class);
                            if(getContact != null){
                                tv_tel.setText(getContact.getContent());
//                                tel = tv_tel.getText().toString().substring(5);
                                tel = tv_tel.getText().toString();
                            }
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /*
     * 设置点击事件
     */
    private void setOnClickListener() {
        ll_tel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectUtils.callByPhone(ContactCustomerServiceActivity.this, tel);
            }
        });
    }

    @SuppressWarnings("unused")
    private View.OnClickListener onClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                default:
                    break;
            }
        }
    };

    /*
     * 初始化view
     */
    private void initView() {
        // 设置顶部的标题
        setTop(null, 0, getString(R.string.top_customer_service), null, 0);
        setBackArrows(findViewById(R.id.top_bar_left_iv));
        ll_tel = (LinearLayout) findViewById(R.id.ll_tel);
        tv_tel = (TextView) findViewById(R.id.tv_tel);



    }

}
